package com.shop.web.menu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shop.web.menu.entity.MakeMenuTree;
import com.shop.web.menu.entity.Menu;
import com.shop.web.menu.mapper.MenuMapper;
import com.shop.web.menu.service.MenuService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements MenuService {
    @Override
    public List<Menu> getParnet() {
        //查询出所有的菜单
        QueryWrapper<Menu> query = new QueryWrapper<>();
        query.lambda().eq(Menu::getType,"1")
        .orderByAsc(Menu::getOrderNum);
        List<Menu> menuList = this.baseMapper.selectList(query);
        //构造顶级菜单
        Menu menu = new Menu();
        menu.setMenuId(0L);
        menu.setParentId(-1L);
        menu.setTitle("顶级菜单");
        menu.setLabel("顶级菜单");
        menu.setValue(0L);
        //添加到菜单数据
        menuList.add(menu);
        //组装树形数据
        return MakeMenuTree.makeTree(menuList,-1L);
    }

    @Override
    public List<Menu> getMenuByUserId(Long userId) {
        return this.baseMapper.getMenuByUserId(userId);
    }
}
